package com.example.mobile2021606185zhn0617;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class WorkerViewAdapter extends RecyclerView.Adapter<WorkerViewAdapter.ViewHolder> {
    List<Worker> list;
    public WorkerViewAdapter(List<Worker> list){
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvName,tvSkill, tvMoney;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tvItemName);
            tvSkill = itemView.findViewById(R.id.tvItemSkill);
            tvMoney = itemView.findViewById(R.id.tvItewMoney);
        }
    }
    @NonNull
    @Override
    public WorkerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_rv_worker, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull WorkerViewAdapter.ViewHolder holder, int position) {
        Worker worker = list.get(position);
        holder.tvName.setText(""+worker.getName());
        holder.tvSkill.setText(""+worker.getSkill());
        holder.tvMoney.setText(""+worker.getMoney());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
